local ShopCard = class("ShopCard")
local TypeHelper = require("utils.TypeHelper")

function ShopCard:ctor()
end

function ShopCard:start()
    self._btnBuy.onClick:AddListener(handler(self, self._onBtnBuyClick))
end

function ShopCard:updateUI(data)
    self._data = data
    self._icon:updateUI(data.item_type, data.item_value, data.item_size)
    local itemParam = self._icon:getItemParam()
    if data.name ~= "" then
        self._textName.text = data.name
    else
        self._textName.text = itemParam.name
    end
    local priceCfg = TypeHelper.getCfg(data.price_type, data.price_value)
    self._textPrice.text = data.price_size .. priceCfg.name
end

function ShopCard:_onBtnBuyClick()
    if not self._data then
        return
    end
    local pop = require("view.shop.PopupShopBuy").new(self._data)
end

return ShopCard
